/*
 * Step 2
 * - Open File
 * - Scan In Numbers
 * - Print Before
 * - Sort Numbers
 * - Print After
 */

#include <stdio.h>
#include <stdlib.h>

#define NUMS_PER_FILE 4



int intcmp(const void *n1, const void *n2)
{
	const int *num1 = (const int *)n1;
	const int *num2 = (const int *)n2;
	return (*num1 < *num2) ? -1 : (*num1 > *num2);
}

int main(int argc, char* argv[])
{
	int i;
  	int numbers[NUMS_PER_FILE];
	FILE *file;

	file = fopen("1.txt", "r");

	printf("\nstart step2.c\n");

	// Scan in numbers
	for(i = 0; i < NUMS_PER_FILE; i++)
	{
		fscanf(file, "%d", &numbers[i]);
	}

	printf("\nbefore sorting\n");	

	// Print numbers before
	for(i = 0; i < NUMS_PER_FILE; i++)
	{
		printf("%d ", numbers[i]);
	}

	printf("\nafter sorting\n");	

	qsort(numbers, NUMS_PER_FILE, sizeof(int), intcmp);

	// Print numbers after
	for(i = 0; i < NUMS_PER_FILE; i++)
	{
		printf("%d ", numbers[i]);
	}

	printf("\nend step2.c\n");

	return 0;
}



